<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class ReportsController extends AppController {

    var $name = 'reports';
    var $components = array(
        'Session'
    );
    var $uses = array(
        'Order'
    );

    function index() {
        $this->set('title_for_layout', Configure::read('site_name') . ' - Báo cáo doanh thu');

        $date_start = !empty($this->params['form']['filter_start_date']) ? $this->params['form']['filter_start_date'] : false;
        $date_end = !empty($this->params['form']['filter_end_date']) ? $this->params['form']['filter_end_date'] : false;
        if($date_start){
            $pre = preg_match('@^([0-9]{1,2})-([0-9]{1,2})-([0-9]{1,4})$@', $date_start, $match);
            $date_start = "{$match[3]}-{$match[2]}-{$match[1]} 00:00:00";
        }
        if($date_end){
            $pre = preg_match('@^([0-9]{1,2})-([0-9]{1,2})-([0-9]{1,4})$@', $date_end, $match);
            $date_end = "{$match[3]}-{$match[2]}-{$match[1]} 00:00:00";
        }
        $this->set('total_price',$this->Order->getTotalPrice($date_start, $date_end));
        $this->set('total_order',$this->Order->getTotalOrder($date_start, $date_end));
        $this->set('total_complete_order',$this->Order->getCompleteOrder($date_start, $date_end));
    }
}

?>
